package cc.vv.baselibrary.util.remind;

import android.app.Activity;
import android.app.Dialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.TextView;

import java.io.Serializable;

import cc.vv.baselibrary.R;
import cc.vv.baselibrary.db.daTable.RemindFunctionObj;
import cc.vv.baselibrary.util.LKDialogUtil;


public class ClockAlarmActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clock_alarm);
        String title = this.getIntent().getStringExtra("title");
        RemindFunctionObj data = (RemindFunctionObj) this.getIntent().getSerializableExtra("data");
        String content = this.getIntent().getStringExtra("content");
        if (null != data) {
            showDialog(this, title, data);
        } else {
            new BCNotification(this).postNotification(title, content);
        }
    }

    /**
     * 显示dialog
     *
     * @param title
     * @param remindFunctionObj
     */
    private void showDialog(final Context context, String title, final RemindFunctionObj remindFunctionObj) {
        View view = View.inflate(this, R.layout.dialog_remind_vew, null);
        TextView tv_remind_content = view.findViewById(R.id.tv_remind_content);
        TextView tv_remind_repeat = view.findViewById(R.id.tv_remind_repeat);
        TextView tv_remind_confirm = view.findViewById(R.id.tv_remind_confirm);
        final Dialog dialog = LKDialogUtil.getDialogWidth(this, view, R.style.Theme_dialog, 0, 280);
        tv_remind_content.setText(title);
        tv_remind_repeat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //重复提醒
                dialog.dismiss();
                long repeatitionTime = 5 * 60 * 1000;
                BCAlarmUtil.setSystemAlarm(context, remindFunctionObj, repeatitionTime);
            }
        });
        tv_remind_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //完成
                dialog.dismiss();
                BCAlarmUtil.setSystemAlarm(context, remindFunctionObj, 0);
            }
        });
        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        });
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }
}
